/* eslint-disable node/prefer-global/process */
// import process from 'node:process'
import { DataSource } from 'typeorm'
import { config } from 'dotenv'
import { User } from './modules/user/entities/user.entity'
import { History } from './modules/user/entities/history.entity'
import { Role } from './modules/role/entities/role.entity'
import { Permission } from './modules/permission/entities/permission.entity'
import { Meeting } from './modules/meeting/entities/meeting.entity'
import { Menu } from './modules/menu/entities/menu.entity'

config({ path: 'src/.env-migration' })

export default new DataSource({
  type: 'mysql',
  host: `${process.env.mysql_server_host}`,
  port: +`${process.env.mysql_server_port}`,
  username: `${process.env.mysql_server_username}`,
  password: `${process.env.mysql_server_password}`,
  database: `${process.env.mysql_server_database}`,
  synchronize: false,
  logging: true,
  entities: [
    User,
    Role,
    Permission,
    Meeting,
    Menu,
    History,
  ],
  poolSize: 10,
  migrations: ['src/migrations/**.ts'],
  connectorPackage: 'mysql2',
  extra: {
    authPlugin: 'sha256_password',
  },
})
